#pragma once

#include <AVUIDispatcher.h>

namespace AVUI {

class FrameworkContextData : public Object
{
private:
    struct WalkerEntry
    {
        void* Data;
        DescendentsWalkerBase* Walker;
    };

public:

    FrameworkContextData() : m_currentWalkers(4) { }

    void AddWalker(void* pData, DescendentsWalkerBase* pWalker)
    {
        WalkerEntry item;
        item.Data = pData;
        item.Walker = pWalker;
        m_currentWalkers.AddItem(item);
    }

    static FrameworkContextData* From(Dispatcher* pContext)
    {
        FrameworkContextData* pData = (FrameworkContextData*) (pContext->get_FrameworkContext());
        if (pData == NULL)
        {
            pContext->set_FrameworkContext(object_allocate<FrameworkContextData>());
            pData = (FrameworkContextData*) (pContext->get_FrameworkContext());
        }
        return pData;
    }

    void RemoveWalker(void* pData, DescendentsWalkerBase* pWalker)
    {
        int index = m_currentWalkers.get_Count() - 1;
        m_currentWalkers.RemoveAt(index);
    }

    bool WasNodeVisited(DependencyObject* pDO, void* pData)
    {
        if (m_currentWalkers.get_Count() > 0)
        {
            int num = m_currentWalkers.get_Count() - 1;
            WalkerEntry entry = m_currentWalkers[num];
            if (entry.Data == pData)
            {
                return entry.Walker->WasVisited(pDO);
            }
        }
        return false;
    }

private:
    ItemStructList<WalkerEntry> m_currentWalkers;
};



}; // namespace AVUI
